<!--
 * @Description: 定位
 * @Author: rendc
 * @Date: 2022-09-23 09:25:00
 * @LastEditors: rendc
 * @LastEditTime: 2022-09-23 09:37:16
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>定位</title>
  <style>
    *{ 
      margin: 0;
      padding: 0;
    }
    .parent{ 
      width: 400px;
      height: 400px;
      background-color: yellowgreen;
      margin: 20px;
      /* 相对定位的原先位置会保留 给子元素提供了定位祖先元素 */
      position: relative;
      z-index: 2;

    }
    .child{ 
      width: 200px;
      height: 200px;
      background-color: hotpink;
      /* 没有定位祖先元素 是相对于视口定位 有了的话 相对于最近的祖先元素定位 */
      position: absolute;
      left: 100px;
      top: 100px;
      z-index: 1;
    }
    .one{ 
      width: 100px;
      height: 100px;
      background-color: skyblue;
      position: absolute;
      left: 100px;
      top: 100px;
      z-index: 1;
    }
  </style>
</head>
<body>
  <div class="parent">
    <div class="child"></div>
  </div>
  <div class="one"></div>
</body>
</html>
